<template>
  <img :src="QRImgUrl" />
</template>

<script>
import QRCode from 'qrcode'
export default {
  data () {
    return {
      QRImgUrl: '',
      QRlink: null
    }
  },
  created () {
    console.log(this.apkUrl)
    if (this.apkUrl) {
      this.QRlink = this.apkUrl
    }
    this.getQRcode()
  },
  props: {
    apkUrl: {
      type: String,
      default: null
    }
  },
  methods: {
    getQRcode () {
      let opts = {
        errorCorrectionLevel: "L",//容错级别
        type: "image/png",//生成的二维码类型
        quality: 1,//二维码质量
        margin: 2,//二维码留白边距
        width: 130,//宽
        height: 130,//高
        color: {
          dark: "#666666",//前景色
          light: "#fff"//背景色
        }
      };
      //this.QRlink 生成的二维码地址url
      QRCode.toDataURL(this.QRlink, opts).then(res => {
        this.QRImgUrl = res
        this.$emit('getImgUrl', this.QRImgUrl)
      })
    }
  }
}
</script>
